package sentimentalAnalyzer;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class AnalyzerInterface {
		
	public static void analyze(String inputPath, String outputPath) throws IOException, InterruptedException, ClassNotFoundException {
		Configuration conf = new Configuration();
		
		Job job = new Job(conf, "test_analyzer");
		job.setJarByClass(AnalyzerInterface.class);
		job.setMapperClass(SentimentalMapper.class);
		job.setReducerClass(SentimentalReducer.class);
		
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(Text.class);
				
		FileInputFormat.addInputPath(job, new Path(inputPath));
		
		FileSystem.get(job.getConfiguration()).delete(new Path(outputPath), true);
		FileOutputFormat.setOutputPath(job, new Path(outputPath));
		
		System.exit(job.waitForCompletion(true) ? 0 : 1);

	}

}
